package com.zzh.jnilearn

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.zzh.jnilearn.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    companion object {
        init {
            System.loadLibrary("native-lib")
        }
    }

    private lateinit var binding: ActivityMainBinding

    var name: String = "a"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)


        //Android获取jni返回值
        binding.btFun1.setOnClickListener {
            binding.sampleText.text = stringFromJNI()
        }

        //jni修改name字段
        binding.btFun2.setOnClickListener {
            jniSetName()
            binding.sampleText.text = name
        }

        binding.btFun3.setOnClickListener {
            invokeJavaCallback()
        }

    }


    external fun stringFromJNI(): String

    external fun jniSetName()

    external fun invokeJavaCallback()

    fun onCallback(code: Int) {
        Toast.makeText(this, "jni code:$code", Toast.LENGTH_SHORT).show()
    }

}